// 测试具体的时间解析案例
const http = require('http')

async function testSpecificCase() {
  console.log('🧪 测试具体的时间解析案例...\n')
  
  const testCase = '下午2点半与财务讨论现金流报表表逻辑'
  console.log(`📝 测试用例: "${testCase}"`)
  
  try {
    const postData = JSON.stringify({ text: testCase })
    
    const options = {
      hostname: 'localhost',
      port: 5000,
      path: '/api/ai/smart-parse',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(postData)
      }
    }
    
    const result = await new Promise((resolve, reject) => {
      const req = http.request(options, (res) => {
        let data = ''
        res.on('data', (chunk) => { data += chunk })
        res.on('end', () => {
          try {
            const parsed = JSON.parse(data)
            resolve({ status: res.statusCode, data: parsed })
          } catch (e) {
            resolve({ status: res.statusCode, data: data })
          }
        })
      })
      
      req.on('error', reject)
      req.write(postData)
      req.end()
    })
    
    console.log(`📊 响应状态: ${result.status}`)
    console.log('📝 完整响应:', JSON.stringify(result.data, null, 2))
    
    if (result.data.result) {
      const r = result.data.result
      console.log('\n📋 解析结果分析:')
      console.log('  标题:', r.title)
      console.log('  日期:', r.dueDate ? `✅ ${r.dueDate}` : '❌ 未解析')
      console.log('  分类:', r.category)
      console.log('  标签:', r.tags?.join(', ') || '无')
      console.log('  备注:', r.notes || '无')
      console.log('  优先级:', r.priority)
      
      if (r.dueDate) {
        const today = new Date().toISOString().split('T')[0]
        if (r.dueDate === today) {
          console.log('✅ 时间解析正确 - 识别为今天')
        } else {
          console.log(`⚠️ 时间解析异常 - 期望今天(${today})，实际${r.dueDate}`)
        }
      } else {
        console.log('❌ 时间解析失败 - 应该识别为今天')
      }
    }
    
  } catch (error) {
    console.log('❌ 测试失败:', error.message)
    if (error.code === 'ECONNREFUSED') {
      console.log('💡 请确保后端服务正在运行')
    }
  }
}

testSpecificCase()
